﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using Architecture.Domain.BankManagement;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Architecture.Domain.TestModel.Models;
using Microsoft.Practices.Unity;
using Architecture.Domain.BankManagement.Repositories;
using Architecture.CrossCutting.RepositoryPattern;
using System.Data.Entity;

namespace Architecture.Domain.BankManagement.Tests
{

    [TestClass()]
    public class BankManagementServicesTests
    {

        UnityContainer _container = new UnityContainer();

        public TestContext TestContext { get; set; }

        [TestInitialize()]
        public void Initialize()
        {
            _container.RegisterType<DbContext, BankManagementContext>(new HierarchicalLifetimeManager());
            //_container.RegisterType(typeof(BankManagementContext), new PerResolveLifetimeManager(), new InjectionConstructor());
            _container.RegisterType<IRepository<Country>, Repository<Country>>();
            _container.RegisterType<IRepository<Client>, Repository<Client>>();
            _container.RegisterType<BankManagementServices>();


        }

        [TestMethod()]
        public void AddCountryTest()
        {
            var country = new Country()
            {
                Name = "NETHERLANDS",
                CodeISO = "NL"
            };

            BankManagementServices service = _container.Resolve<BankManagementServices>();
            Country persistedCountry = service.AddCountry(country);


        }

        [TestMethod()]
        [DeploymentItem("data.csv"), DeploymentItem(@"EntityFramework.SqlServer.dll")]
        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\data.csv", "data#csv", DataAccessMethod.Sequential)]
        public void CreateClientTest()
        {
            BankManagementServices service = _container.Resolve<BankManagementServices>();
            var country = service.GetCountry(this.TestContext.DataRow["Country"].ToString());

            var client = new Client()
            {
                Birthday = DateTime.Parse(this.TestContext.DataRow["Birthday"].ToString()),
                FirstName = this.TestContext.DataRow["FirstName"].ToString(),
                LastName = this.TestContext.DataRow["LastName"].ToString(),
                Nationality = country
            };

            service.CreateClient(client);

            //Assert.Fail();
        }
    }
}